{% extends 'list.html' %}

{% block active_users %}active{% endblock %}

{% block header_buttons %}
<a href="{% url 'auth.views.create_user' %}" class="btn btn-primary pull-right" type="button"><i class="icon-plus icon-white"></i> Add a New User</a>
{% endblock %}

{% block legend %}
Filter the List of Users
{% endblock %}

{% block form_action %}/auth/users/{% endblock %}

{% block filter_help %}Search for Users{% endblock %}
{% block search_for %}Users{% endblock %}

{% block specialised_controls %}
<!-- Filtering on group membership -->
<div class="control-group">
	<label class="control-label" for="group">
		In Group
	</label>
	<div class="controls">
		<select id="group" name="group" class="input-large" type="select">
			<option>All Groups</option>
		{% for group in groups %}
			<option {% if filter_group and filter_group == group.name %} selected="selected"{% endif %}>{{ group.name }}</option>
		{% endfor %}
		</select>
	</div>
</div>

<input type="hidden" name="page" value="{{ users.number }}" />
{% endblock %}

{% block filter_buttons %}
	<button type="submit" class="btn btn-primary" type="button">Filter Users</button>
	<a href="{% url 'auth.views.list_users' %}" class="btn" type="button">Clear Filter</a>
{% endblock %}


{% block table_headings %}
<th>#</th>
<th id="first-name">First Name</th>
<th id="last-name">Last Name</th>
<th id="username">Username</th>
<!--<th id="lowest-score">Lowest Score</th>-->
<th id="registration-date">Registration Date</th>
<th id="last-login">Last Login</th>
<th>Group(s)</th>
<th style="text-align: center;">Edit</th>
<th style="text-align: center;">Trash</th>
{% endblock %}

{% block table_body %}
{% if users %}
  	{% for user in users %}
   		{% if user.is_active %}
	    	<tr>
	    		<td>{{ forloop.counter }}</td>
		    	<td>{{ user.first_name }}</td>
		    	<td>{{ user.last_name }}</td>
		    	<td><a href="{% url 'auth.views.view_user' username=user.username %}">{{ user.username }}</a></td>
	    		{% comment %}
		    	<td>
					<div class="progress progress-success">
						<div class="bar" style="width: 95%">95 %</div>
					</div>
				</td>
				{% endcomment %}
		    	<td>{{ user.date_joined|date:"Y-m-d" }}</td>
		    	<td>{{ user.last_login|date:"M Y" }}</td>
		    	<td>
	    		{% for group in user.groups.all %}
	    			{% url 'auth.views.list_users' as group_url %}
	    			<a href='{{ group_url }}?group={{ group.name.split|join:"+" }}'>{{ group }}</a>{% if not forloop.last %},{% endif %}
	    		{% endfor %}
		    	</td>
		    	<td style="text-align: center;"><a href="{% url 'auth.views.edit_user' username=user.username %}"><i class="icon-edit"></i></a></td>
		    	<td style="text-align: center;"><a href="{% url 'auth.views.trash_user' username=user.username %}"><i class="icon-trash"></i></a></td>
		    </tr>
	    {% endif %}
	{% endfor %}
	{% else %}
	   	<tr class="info">
	   		<td colspan="9">No users to display</td>
	   	</tr>
	{% endif %}
{% endblock %}

{% block pagination %}
{% load pagination %}
{% paginate users %}
{% endblock %}